﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JQueryRotate.aspx.cs" Inherits="JQueryRotate.JQueryRotate" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery.min.js" type="text/javascript"></script>
    <script src="Scripts/jQueryRotate.2.2.js" type="text/javascript"></script>
    <script src="Scripts/jquery.easing.min.js" type="text/javascript"></script>
    <style type="text/css">
        *{padding:0;margin:0}
        body{
            text-align: center;
            background-color: #1664ad;
        }
        .ly-plate{
            position:relative;
            width:509px;
            height:509px;
            margin: 50px auto;
        }
        .rotate-bg{
            width: 509px;
            height: 509px;
            background: url(Images/ly-plate.png);
            position: absolute;
            top: 0;
            left: 0;
            margin-top: 0%;
        }
        .ly-plate div.lottery-star{
            width:214px;
            height:214px;
            position:absolute;
            top:150px;
            left:147px;
            /*text-indent:-999em;
            overflow:hidden;
            background:url(rotate-static.png);
            -webkit-transform:rotate(0deg);*/
            outline:none
        }
        .ly-plate div.lottery-star #lotteryBtn{
            cursor: pointer;
            position: absolute;
            top:0;
            left:0;
            *left:-107px
        }
    </style>
    <script type="text/javascript">
        $(function () {
            var timeOut = function () {  //超时函数
                $("#lotteryBtn").rotate({
                    angle: 0,
                    duration: 10000,
                    animateTo: 2160, //这里是设置请求超时后返回的角度，所以应该还是回到最原始的位置，2160是因为我要让它转6圈，就是360*6得来的
                    callback: function () {
                        alert('网络超时')
                    }
                });
            };
            var rotateFunc = function (angle, text) {  //angle:奖项对应的角度
                $('#lotteryBtn').unbind("click"); //移除click
                $('#lotteryBtn').stopRotate();
                $("#lotteryBtn").rotate({
                    angle: 0,
                    duration: 5000,
                    animateTo: angle + 1440, //angle是图片上各奖项对应的角度，1440是我要让指针旋转4圈。所以最后的结束的角度就是这样子^^
                    callback: function () {
                        alert(text)
                        $('#lotteryBtn').bind("click", clickFunc);
                    }
                });
            };

            var clickFunc = function () {
                $.post("RandRotate.ashx", {}, function (result) {
                    var obj = JSON.parse(result);
                    rotateFunc(obj.Angle, obj.Message);
                });
            };

            $("#lotteryBtn").rotate({
                bind:
                {
                    click: clickFunc
                }
            });
        })
    </script>   
</head>
<body>
    <form id="form1" runat="server">
    <div class="ly-plate">
    <div class="rotate-bg"></div>
        <div class="lottery-star">
            <img src="Images/rotate-static.png" id="lotteryBtn" alt="开始抽奖">
        </div>
    </div>
    </form>
</body>
</html>
